package com.yidu.ruifeng_logistics.service.impl;

import com.yidu.ruifeng_logistics.entity.LogisticsRoleModel;
import com.yidu.ruifeng_logistics.dao.LogisticsRoleModelDao;
import com.yidu.ruifeng_logistics.service.LogisticsRoleModelService;
import com.yidu.ruifeng_logistics.vo.LogisticsRoleModelVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (LogisticsRoleModel)表服务实现类
 *
 * @author 张皓超
 * @since 2021-03-09 14:29:11
 */
@Service("logisticsRoleModelService")
public class LogisticsRoleModelServiceImpl implements LogisticsRoleModelService {
    @Resource
    private LogisticsRoleModelDao logisticsRoleModelDao;

    /**
     * 通过ID查询单条数据
     *
     * @param roleModelId 主键
     * @return 实例对象
     */
    @Override
    public LogisticsRoleModel queryById(Integer roleModelId) {
        return this.logisticsRoleModelDao.queryById(roleModelId);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<LogisticsRoleModel> queryAllByLimit(int offset, int limit) {
        return this.logisticsRoleModelDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param logisticsRoleModel 实例对象
     * @return 实例对象
     */
    @Override
    public LogisticsRoleModel insert(LogisticsRoleModel logisticsRoleModel) {
        this.logisticsRoleModelDao.insert(logisticsRoleModel);
        return logisticsRoleModel;
    }

    /**
     * 修改数据
     *
     * @param logisticsRoleModel 实例对象
     * @return 实例对象
     */
    @Override
    public LogisticsRoleModel update(LogisticsRoleModel logisticsRoleModel) {
        this.logisticsRoleModelDao.update(logisticsRoleModel);
        return this.queryById(logisticsRoleModel.getRoleModelId());
    }

    /**
     * 通过主键删除数据
     *
     * @param roleModelId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer roleModelId) {
        return this.logisticsRoleModelDao.deleteById(roleModelId) > 0;
    }

    @Override
    public List<LogisticsRoleModel> queryAll(LogisticsRoleModel logisticsRoleModel) {
        return this.logisticsRoleModelDao.queryAll(logisticsRoleModel);
    }

    @Override
    public List<LogisticsRoleModel> queryRoleIdReturnRoleModelId(int roleId) {
        return this.logisticsRoleModelDao.queryRoleIdReturnRoleModelId(roleId);
    }

    @Override
    public LogisticsRoleModelVo selectByIdReturnVo(Integer roleModelId) {
        return this.logisticsRoleModelDao.selectByIdReturnVo(roleModelId);
    }

    @Override
    public List<LogisticsRoleModelVo> selectAllVo() {
        return this.logisticsRoleModelDao.selectAllVo();
    }

    @Override
    public int addAndUpdate(Integer roleModelId,Integer roleId, String name) {
        int i=0;
        if (roleId!=null&&name!=null&&name!="") {
            String[] split = name.split(",");
            if (roleModelId != null) {
                //修改
                LogisticsRoleModel logisticsRoleModel = logisticsRoleModelDao.queryById(roleModelId);
                i = logisticsRoleModelDao.deleteroleId(logisticsRoleModel.getRoleId());
                i = logisticsRoleModelDao.insertAll(split, roleId);
            } else {
                //增加
                i = logisticsRoleModelDao.insertAll(split, roleId);
            }
            return i;
        }else{
            return i;
        }
    }

    @Override
    public List<Integer> selectRoleIdReturnModelId(Integer roleId) {
        return this.logisticsRoleModelDao.selectRoleIdReturnModelId(roleId);
    }

    @Override
    public List<LogisticsRoleModel> queryRoleIdReturnRoleModelIdNoIsNull(int roleId) {
        return this.logisticsRoleModelDao.queryRoleIdReturnRoleModelIdNoIsNull(roleId);
    }


}
